package com.steven.sync;

import java.util.concurrent.locks.LockSupport;

/**
 * 停止，叫醒指定的线程
 * unpark 可以在park之前调用， 后面不能挺住
 */
public class LockSupport_test {
    public static void main(String[] args) {
      Thread thread =   new Thread(() -> {
          for (int i = 0; i < 10; i++) {
              try {
                  if(i==5){
                      LockSupport.park();
                  }
                  Thread.sleep(1000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              System.out.println(i);
          }
      });
        thread.start();
        try {
            Thread.sleep(20000);
            LockSupport.unpark(thread);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
